Many computer programs require maintaining a running count of active events. Active events may be conditions, states, external processes, essentially any entity that needs to be counted along with the necessity for the number of these active at any given time to be known to a program or process. In a single processor system, this may be implemented with a simple counter, which is incremented when an event is started and decremented when an event completes. This same simple counter method may also be used in a multi-processor system under two conditions: 1) A single executing process is used to both start and complete the events (and update the counter); or 2) Two different executing processes are used, one to start events and another to complete events. In the latter case, a spin lock must be obtained by either process before updating the counter to ensure that the other process is not executing at that time. A spin lock being a lock that a processor is continuously trying to acquire, spinning around a loop, in order to perform/execute the process. An exemplary spin lock dependent system may be seen in FIG. 1.
On a multi-processor system it is more efficient to use multiple processes to perform tasks, as multiple processes can run simultaneously (in parallel). However, with the separate Start and Complete event processes shown in FIG. 1, it is necessary to utilize a spin lock to “synchronize” the two processes together before updating the counter. Each process must acquire (own) the spin lock before proceeding. If the spin lock is already owned by another process, the acquiring process will wait until the spin lock is released by the other process. This results in wasted processor cycles and causes these two processes to run as if they were a single executing process (no parallel execution).
If no spin lock is used with two separate processes, there is the possibility that both processes may read the counter at about the same time, and then each process would update the value and write it back to the counter. Whichever process wrote their value back last would overwrite the value of the other process, thereby losing the counter update of that process.
It is much more efficient to allow both of these processes to run in parallel. Therefore, it would be desirable to provide different method for maintaining a running count of active events.